package main

import (
	"fmt"
	"strings"
)

func main() {

	// 破解int类型秘密示例
	//var paswd int
	//fmt.Println("请输入3位纯数字密码：")
	//fmt.Scanln(&paswd)
	//rest, err := CrackIntPassword(paswd)
	//if err != nil {
	//	fmt.Println("发生错误：", err)
	//}
	//
	//fmt.Println("您输入的密码是：", rest)

	// 破解字符串密码
	password := ""
	fmt.Println("请输入3位纯数字密码：")
	fmt.Scanln(&password)
	rest := CrackStrPassword(password)

	fmt.Println("您输入的密码是：", rest)
}

// 破解数字秘密
func CrackIntPassword(paswd int) (int, error) {
	var userPaswd int
	for ; userPaswd < paswd; userPaswd++ {
		fmt.Println("尝试：", userPaswd)
	}

	return userPaswd, nil
}

// 破解字符串密码 a1b,
func CrackStrPassword(passowrd string) string {
	retPwd := ""
	pwds := strings.Split(passowrd, "")
	for _, item := range pwds {
		for i := 0; i <= 999; i++ {
			pwd := fmt.Sprintf("%d", i)
			if pwd == item {
				retPwd = retPwd + item
			}
		}
	}

	return retPwd
}
